package com.itheima_01.day09;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListTest {
    public static void main(String[] args) {
        //addTest();
        //getTest();
        removeTest();
        // setTest();
       /* Student stu1 = getStudent();
        Student stu2 = getStudent();
        Student stu3 = getStudent();*/

        /*
        ---------------------------------------------
         */

       /* ArrayList<Student> list = new ArrayList<>();//创建集合
        *//*list.add(stu1);
        list.add(stu2);
        list.add(stu3);*//*
        for (int i = 0; i < 3; i++) {
            Student stu = getStudent();
            list.add(stu);
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getName() + "..." + list.get(i).getAge());
        }*/
    }

    private static void setTest() {
        ArrayList<String> list = new ArrayList();
        list.add("abc");
        list.add("111");
        list.add("222");
        list.add("333");
        list.add("444");
        list.add("555");
        String s = list.set(1, "666");
        System.out.println(list);
    }

    private static void removeTest() {
        ArrayList<String> list = new ArrayList();
        list.add("test");
        list.add("111");
        list.add("222");
        list.add("333");
        list.add("test");
        list.add("test");
        System.out.println("删除前：");
        System.out.println(list);
        System.out.println("长度为：");
        System.out.println(list.size());
        for (int i = list.size() - 1; i >= 0; i--) {
            if("test".equals(list.get(i))){
                list.remove(i);
            }
        }
        System.out.println("删除后：");
        System.out.println(list);
        System.out.println("长度为：");
        System.out.println(list.size());
    }

    private static void getTest() {
        ArrayList<String> list = new ArrayList();
        list.add("abc");
        list.add("111");
        list.add("222");
        list.add("333");
        list.add("444");
        list.add("555");
        String s = list.get(3);
        System.out.println(s);
        System.out.println(list);
    }

    public static void addTest() {
        ArrayList<String> list = new ArrayList();
        list.add("abc");
        list.add("111");
        list.add("222");
        list.add("333");
        list.add("444");
        list.add("555");
        list.add(3, "woainimb");
        int s = list.size();
        System.out.println(s);
        System.out.println(list);
    }

    public static Student getStudent() {
        System.out.println("请输入学生姓名：");
        Scanner sc = new Scanner(System.in);
        String string = sc.next();
        System.out.println("请输入学生年龄：");
        Scanner sc1 = new Scanner(System.in);
        int age = sc1.nextInt();
        Student stu = new Student(string, age);
        return stu;
    }

}
